import { _decorator, assetManager, Canvas, Component, debug, director, JsonAsset, Label, Node, profiler, resources, Settings, settings, Sprite, sys } from 'cc';
import DataManager from './DataManager';
const { ccclass, property } = _decorator;

@ccclass('Loading')
export class Loading extends Component {
    @property(Label)
    private mLoadTxt:Label=null;
    @property(Label)
    private mProssTxt:Label=null;
    @property(Sprite)
    private mProSprite:Sprite=null;
    protected onEnable(): void {
        let tself = this;
        resources.load("cfg/gateCfg",(pro1,pro2)=>{
            tself.updatePross(pro1/pro2);
            console.log(pro1,pro2);
        },(err,assets:JsonAsset)=>{
            console.log("ss",err);
            if(err)return;
            DataManager.ins.setGameCfg(assets.json);
            tself.goGame();
        });

        this.loadSpGates();
        //settings.overrideSettings(Settings.Category.PROFILING,'showFP', true)
       
    }

    private mIsLoadScene:boolean=false;
    private mLoadProTest:number=0.01;
    private goGame(){
        this.mIsLoadScene=true;
        let tself=this;
        director.loadScene("scenes/Game.scene",()=>{
            tself.mIsLoadScene=false;
        });
    }

    protected update(dt: number): void {
        if(this.mIsLoadScene){
            if(this.mLoadProTest>=1)return;
            this.mLoadProTest += 0.005;
            if(this.mLoadProTest>1)this.mLoadProTest=1;
            this.updatePross(this.mLoadProTest);
        }
    }

    private updatePross(pross:number){
       this.mProSprite.fillRange=pross; 
       this.mProssTxt.string=Math.floor(pross*100)+"%";
    }

    private loadSpGates(){
        resources.load("cfg/specialCfg",(pro1,pro2)=>{
          
        },(err,assets:JsonAsset)=>{
            if(err)return;
            DataManager.ins.setSpGameCfg(assets.json);
        });
    }
   
   
}


